package com.cw2.behavioral.memento;

import org.springframework.beans.BeanUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 游戏服务器
 */
public class GameServer {
    /**
     * 备忘录信息
     */
    Map<Integer, GameRecord> records = new HashMap<Integer, GameRecord>();

    int i = 1;

    /**
     * 添加进备忘录
     * @param gameRecord  游戏记录
     */
    void add(GameRecord gameRecord){
        gameRecord.setId(i);
        records.put(gameRecord.getId(), gameRecord);
        i ++;
    }

    LeiGamer getRecord(Integer id){
        GameRecord gameRecord = records.get(id);
        // 获取到备忘录里面的内容以后还要逆转

        LeiGamer leiGamer = new LeiGamer();
        BeanUtils.copyProperties(gameRecord, leiGamer);
        return leiGamer;
    }
}
